package cn.edu.scau.cmi.chenyuanying.spring.view;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

import org.springframework.context.ApplicationContext;

import cn.edu.scau.cmi.chenyuanying.spring.domain.Student;
import cn.edu.scau.cmi.chenyuanying.spring.domain.Teacher;
import cn.edu.scau.cmi.chenyuanying.spring.util.ApplicationContextUtil;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

public class SpringController implements Initializable {
	private @FXML AnchorPane mainPane;
	private @FXML AnchorPane onePane;
	private @FXML Button one;
	private @FXML Button two;
	private @FXML Button back;
	private @FXML TextArea oneTextArea;
	
	public void clickOne(ActionEvent e) {
		mainPane.setVisible(false);
		onePane.setVisible(true);
		ApplicationContext ac = ApplicationContextUtil.getApplicationContext();
		Student student = (Student)ac.getBean("zhangsan");
		Teacher teacher = (Teacher)ac.getBean("Mr.liang");
		oneTextArea.clear();
		oneTextArea.appendText(student.toString() + "\n" + teacher.toString());
	}
	
	public void clickTwo(ActionEvent e) throws IOException {
		Parent root = FXMLLoader.load(getClass().getResource("/cn/edu/scau/cmi/chenyuanying/spring/view/SpringHibernateStage.fxml"));
		Stage stage = new Stage();
		stage.setTitle("Spring管理DAO对象");
		stage.setScene(new Scene(root));
		stage.show();
	}
	
	public void clickBack(ActionEvent e) {
		mainPane.setVisible(true);
		onePane.setVisible(false);
	}
	
	@Override
	public void initialize(URL location, ResourceBundle resources) {
		mainPane.setVisible(true);
		onePane.setVisible(false);
	}

}
